package com.sun.springbootelasticsearch.controller;

import com.sun.springbootelasticsearch.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class IndexContyroller {

    @Autowired
    private ContentService contentService;


    @GetMapping({"index", "/"})
    public String index() {
        return "index";
    }


    @GetMapping("/parse/{keyword}")
    @ResponseBody
    public boolean parse(@PathVariable("keyword") String keyword) throws IOException {
        return contentService.parseHtml(keyword);
    }


    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    @ResponseBody
    public List<Map<String, Object>> parse(@PathVariable("keyword") String keyword, @PathVariable("pageNo") int pageNo,
                                           @PathVariable("pageSize") int pageSize) throws IOException {
        return contentService.searchPage(keyword, pageNo, pageSize);
    }
}
